<?php
// View for calendar
require_once WACT_ROOT.'controller/controller.inc.php';
require_once WACT_ROOT .'controller/form.inc.php';
require_once WACT_ROOT.'view/view.inc.php';
require_once WACT_ROOT .'view/formview.inc.php';

require_once APP_ROOT . 'view/common/layout.formview.php';
require_once APP_ROOT . 'view/common/layout.view.php';
require_once APP_ROOT . 'include/inc.config.php';

require_once 'model/common/user.php';
require_once 'model/common/event.php';
require_once 'model/common/categories.php';
require_once 'model/common/date.php';
require_once 'model/common/site.php';

class CalendarView extends LayoutFormView {

	//var $form; // form controller

 

    function CalendarView($TemplateFile) {
        parent :: LayoutFormView($TemplateFile);
    }




    function prepare(&$controller, &$request, &$responseModel) {
    	parent::prepare($controller, $request, $responseModel);
        
        
		$this->Template->set('SITE_CSS',Site::getSiteTemplateCSS());
		$this->Template->set('SITE_BASE',Site::getSiteTemplateBase());
		$this->Template->set('SITE_TITLE',Site::getTitle());
		$this->Template->set('title',Site::getTitle().' - Sporting News - Events calendar');


   
    	$tz =& new MyTimeZone();
    	$now = $tz->timeNowLocal();
    	//print 'Preparing page...';
    	//$docbase = HOST;
		//$this->Template->set('docbase',$docbase);
		$app_name = APP_NAME;
		$this->Template->set('app_name',$app_name);
    	$template =& $this->Template;
    

    	$month = $responseModel->get('month');
    	$year = $responseModel->get('year');
    	$selected_date =  gmmktime(0, 0, 0, $month, 1, $year);
    	$date_info = getdate($selected_date);
        $firstDay = $date_info['wday']+1;

        //print "first day:".$firstDay;

        $lastday_date =  gmmktime(0, 0, 0, $month+1, 0, $year);
        $date_info = getdate($lastday_date);
        $numDays = $date_info['mday'];

    	$this->Template->set('month',$month);  // selected month
        $this->Template->set('year',$year);    // selected year
        $this->Template->set('firstDay',$firstDay);
        $this->Template->set('numDays',$numDays);

        //populate combos
        $month_combo =& $this->Template->getChild('month');
        $year_combo =& $this->Template->getChild('year');
        $years =& SportDate::getYears();
        $months =& SportDate::getMonths();
        $month_combo->setChoices($months);
        $year_combo->setChoices($years);



        $current_month = (integer)gmdate('m',$now);
        $this->Template->set('current_month',$current_month);
        $current_year = (integer)gmdate('Y',$now);
        $this->Template->set('current_year',$current_year);

        $prevmonth = gmmktime(0, 0, 0, $month-1  , 1, $year);
        $nextmonth = gmmktime(0, 0, 0, $month+1  , 1, $year);
        $prevyear = gmmktime(0, 0, 0, $month, 1, $year-1);
        $nextyear = gmmktime(0, 0, 0, $month, 1, $year+1);

        $prevmonth_year = (integer)gmdate('Y',$prevmonth);
        $prevmonth_month = (integer)gmdate('m',$prevmonth);
        $nextmonth_year = (integer)gmdate('Y',$nextmonth);
        $nextmonth_month = (integer)gmdate('m',$nextmonth);

        $prevyear_year = (integer)gmdate('Y',$prevyear);
        $prevyear_month = (integer)gmdate('m',$prevyear);
        $nextyear_year = (integer)gmdate('Y',$nextyear);
        $nextyear_month = (integer)gmdate('m',$nextyear);

        $prevmonth_name = SportDate::getMonth($prevmonth_month);
        $nextmonth_name = SportDate::getMonth($nextmonth_month);
        $month_name = SportDate::getMonth($month);

        $this->Template->set('prevmonth_year',$prevmonth_year);
        $this->Template->set('prevmonth_month',$prevmonth_month);
        $this->Template->set('nextmonth_year',$nextmonth_year);
        $this->Template->set('nextmonth_month',$nextmonth_month);
        $this->Template->set('prevyear_year',$prevyear_year);
        $this->Template->set('prevyear_month',$prevyear_month);
        $this->Template->set('nextyear_year',$nextyear_year);
        $this->Template->set('nextyear_month',$nextyear_month);

        $this->Template->set('nextmonth_name',$nextmonth_name);
        $this->Template->set('prevmonth_name',$prevmonth_name);
        $this->Template->set('month_name',$month_name);

        $events =& PendingEvent::getPendingEventsForMonth($month,$year);
        $this->Template->setChildDataSource('List', $events);


    	return;

   }

}






?>
